﻿using Authorization.Center.Controllers;
using Authorization.Center.SqlServer;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.Archives.Api.Application.Command;
using S.Archives.Api.Application.Command.Present;
using S.Archives.Domain.S.ArchivesDto;
using S.Archives.Infrstructre.InterFace;


namespace S.Archives.Api.Controllers
{
    [Route("api/[controller]")]
   
    [ApiController]
    
    public class SheepFileModelController : BaseController
    {
        private IMediator mediator;
        public SheepFileModelController(IMediator mediator, MySqlDbContext db) : base(db)
        {
            this.mediator = mediator;
        }
        [Authorize]
        [HttpGet("Name")]
        public IActionResult Name()
        {
            return Ok(UserStrategyDto.UserTrueName);
        }

        /// <summary>
        /// 新增羊只档案(种公,种母,后裔)
        /// </summary>
        /// <returns></returns>
        /// 
        [HttpPost("AddSheepFile")]
       public async Task<IActionResult> AddSheepFile(SheepFileCreateCommand sheep)
        {
            sheep.CreateBy = UserStrategyDto.UserTrueName;
            var result=await mediator.Send(sheep);
            return Ok(result);
        }
        /// <summary>
        /// 获取分布式配置中心配置内容
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("apollo")]
        public IActionResult ApolloTest([FromServices] IConfiguration configuration, string key)
        {
            return Content(configuration.GetValue<string>(key));
        }
        /// <summary>
        /// 修改羊只档案状态
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        /// 
        [HttpPut("SheepFileUpdateState")]
        public async Task<IActionResult> SheepFileUpdateState(SheepFileUpdateStateCommand t)
        {
            
            var reault= await mediator.Send(t);
            return Ok(reault);
        }
        /// <summary>
        /// 修改羊只档案
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        /// 
        [HttpPut("SheepFileUpdate")]
        public async Task<IActionResult> SheepFileUpdate(SheepFileUpdateCommand t)
        {
            t.UpdateDate = DateTime.Now;
            t.UpdateBy = UserStrategyDto.UserTrueName;
            var reault = await mediator.Send(t);
            return Ok(reault);
        }
        /// <summary>
        /// 批量修改羊只状态
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        /// 
        [HttpPut("SheepFileUpdateStatePL")]
        public async Task<IActionResult> SheepFileUpdateStatePL(SheepFileUpdateStatePLCommand t)
        {
            var reault = await mediator.Send(t);
            return Ok(reault);
        }
        /// <summary>
        /// 批量添加羊只档案
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        /// 
        [HttpPost("SheepFileCreatePL")]
        public async Task<IActionResult> SheepFileCreatePL(SheepFileCreatePLCommand t)
        {
            var reault = await mediator.Send(t);
            return Ok(reault);
        }
        /// <summary>
        /// 修改繁殖状态
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        [HttpPut("ReproductiveStateEdit")]
        public async Task<IActionResult> ReproductiveStateEdit(ReproductiveStateEditCommand t)
        {
            var reault = await mediator.Send(t);
            return Ok(reault);
        }
        /// <summary>
        /// 修改流转状态
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        /// 
        [HttpPut("WanderStateEdit")]
        public async Task<IActionResult> WanderStateEdit(WanderStateEditCommand t)
        {
            var reault = await mediator.Send(t);
            return Ok(reault);
        }
        /// <summary>
        /// 批量修改流转状态
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        [HttpPut("WanderStateEditPL")]
        public async Task<IActionResult> WanderStateEditPL(WanderStateEditPLCommand t)
        {
            var reault = await mediator.Send(t);
            return Ok(reault);
        }
        /// <summary>
        /// 羊只转种
        /// </summary>
        /// <param name="EarTag">可视耳号集合</param>
        /// <returns></returns>
        [HttpPut("TransplantStateEditPL")]
        public async Task<IActionResult> TransplantStateEditPL(List<string> EarTag)
        {
            var reault = await mediator.Send(new TransplantStateEditCommand() {EarTag= EarTag });
            return Ok(reault);
        }
        /// <summary>
        /// 修改状态羊只类型(撤销转种)
        /// </summary>
        /// <param name="EarTag"></param>
        /// <returns></returns>
        [HttpPost("SheepFileEdit")]
        public async Task<IActionResult> SheepFileEdit(string EarTag)
        {
            var reault = await mediator.Send(new SheepFileEditCommand() { EarTag = EarTag });
            return Ok(reault);
        }
        /// <summary>
        /// 批量动态修改在场状态
        /// </summary>
        /// <param name="presents"></param>
        /// <returns></returns>
        [HttpPut("PresentStatePL")]
        public async Task<IActionResult> PresentStatePL(List<PresentStateDynamicDto> presents)
        {
            var reault = await mediator.Send(new PresentStatePLCommand() {Present= presents });
            return Ok(reault);
        }
       /// <summary>
       /// 批量删除羊只档案
       /// </summary>
       /// <param name="ids"></param>
       /// <returns></returns>
        [HttpDelete("SheepFilePLDelete")]
        public async Task<IActionResult> SheepFilePLDelete(string ids)
        {
            var reault = await mediator.Send(new SheepFilePLDeleteCommand() {Id=ids});
            return Ok(reault);
        }
        /// <summary>
        /// 批量直接删除
        /// </summary>
        /// <param name="ids">档案主键Ids</param>
        /// <returns></returns>
        [HttpDelete("SheepFileDeletedirectPL")]
        public async Task<IActionResult> SheepFileDeletedirectPL(string ids)
        {
            var reault = await mediator.Send(new SheepFileDeletedirectPLCommand() { Ids = ids });
            return Ok(reault);
        }
      
    }
}
